/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package co.edu.unal.bioingenium.kbmed.retrieval.vo;

import co.edu.unal.bioingenium.kbmed.features.CompactFeatureVector;
import co.edu.unal.bioingenium.kbmed.text.representation.vo.*;
import gnu.trove.map.TObjectIntMap;
import gnu.trove.map.hash.TObjectIntHashMap;
import java.util.Set;

/**
 *
 * @author Alejandro Riveros Cruz Riveros Cruz
 */
public class QueryDocument {

    /**
     * The query string
     */
    private String queryString = "";
    /**
     * The feature vector
     */
    private CompactFeatureVector featureVector;
    /**
     * The query wordList Map<String,Count> 
     */
    private TObjectIntMap<String> queryWordList;

    /**
     * Builds a query document from the given string 
     * @param queryString 
     */
    public QueryDocument(String queryString) {
        this.queryString = queryString;
    }


    public void clearPrevisuData() {
        queryString = "";
        queryWordList.clear();
        featureVector = null;
    }

    /**
     * Returns an inverted list in which the keys are the words and the values are the index in the feature vectors.
     * @param corpus 
     * @return 
     */
    public TObjectIntMap<String> getInvertedQueryWordList(Corpus corpus) {
        TObjectIntMap<String> invertedSortedWordList = corpus.getInvertedSortedWordList();
        TObjectIntMap<String> invertedQueryWordList = new TObjectIntHashMap<String>();
        for (String word : queryWordList.keySet()) {
            invertedQueryWordList.put(word, invertedSortedWordList.get(word));
        }
        return invertedQueryWordList;
    }

    /**
     * @return the query
     */
    public String getQueryString() {
        return queryString;
    }

    /**
     * @param query the query to set
     */
    public void setQueryString(String query) {
        this.queryString = query;
    }

    /**
     *
     * @return 
     */
    public CompactFeatureVector getFeatureVector() {
        return featureVector;
    }

    /**
     *
     * @param featureVector 
     */
    public void setFeatureVector(CompactFeatureVector featureVector) {
        this.featureVector = featureVector;
    }

    /**
     *
     * @return 
     */
    public TObjectIntMap<String> getWordList() {
        return queryWordList;
    }

    /**
     *
     * @param wordList 
     */
    public void setWordList(TObjectIntMap<String> wordList) {
        this.queryWordList = wordList;
    }

    /**
     * 
     * @param word
     * @return
     */
    public int getWordOccurrences(String word) {
        return queryWordList.get(word);
    }

    /**
     * 
     * @return
     */
    public int getTotalWords() {
        return queryWordList.size();
    }
}
